import request from '@/utils/request'
import config from "@/utils/config"
import { getToken } from '@/utils/auth'
const service = {
	post(url, data = {}) {
		return request({
			url: url,
			method: 'post',
			data: data,
			// params: data
		})
	},
	put(url, data = {}) {
		return request({
			url: url,
			method: 'put',
			data: data,
			params: data
		})
	},
	get(url, params = {}) {
		return request({
			url: url,
			method: 'get',
			params: params
		})
	},
	uploadFile(tempFilePath, url = "/system/oss/upload") {
		return new Promise((resolve, reject) => {
			uni.uploadFile({
				url: config.baseUrl + url, //仅为示例，非真实的接口地址
				filePath: tempFilePath,
				name: 'file',
				header: {
					'Authorization': 'Bearer ' + getToken()
				},
				// formData: {
				// 	'signature': getSignature()
				// },
				success: (res) => {
					console.log(res)
					if(res.statusCode==200) {
						resolve(JSON.parse(res.data));
					}
					else {
						reject(res);
					}
					 
				},
				fail(err) {
					reject(err);
				}
			});
		});
	}
}

export default service